home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / xemacs.info-10.z / xemacs.info-10
Encoding:
GNU Info File  |  1998-05-21  |  46.5 KB  |  1,093 lines

  1. This is Info file ../../info/xemacs.info, produced by Makeinfo version
  2. 1.68 from the input file xemacs.texi.
  3.  
  4.    This file documents the XEmacs editor.
  5.  
  6.    Copyright (C) 1985, 1986, 1988 Richard M. Stallman.  Copyright (C)
  7. 1991, 1992, 1993, 1994 Lucid, Inc.  Copyright (C) 1993, 1994 Sun
  8. Microsystems, Inc.  Copyright (C) 1995 Amdahl Corporation.
  9.  
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.  
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided also
  16. that the sections entitled "The GNU Manifesto", "Distribution" and "GNU
  17. General Public License" are included exactly as in the original, and
  18. provided that the entire resulting derived work is distributed under the
  19. terms of a permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that the sections entitled "The GNU Manifesto",
  24. "Distribution" and "GNU General Public License" may be included in a
  25. translation approved by the author instead of in the original English.
  26.  
  27. 
  28. File: xemacs.info,  Node: Lists,  Next: Defuns,  Prev: Program Modes,  Up: Programs
  29.  
  30. Lists and Sexps
  31. ===============
  32.  
  33.    By convention, Emacs keys for dealing with balanced expressions are
  34. usually `Control-Meta-' characters.  They tend to be analogous in
  35. function to their `Control-' and `Meta-' equivalents.  These commands
  36. are usually thought of as pertaining to expressions in programming
  37. languages, but can be useful with any language in which some sort of
  38. parentheses exist (including English).
  39.  
  40.    The commands fall into two classes.  Some commands deal only with
  41. "lists" (parenthetical groupings).  They see nothing except
  42. parentheses, brackets, braces (depending on what must balance in the
  43. language you are working with), and escape characters that might be used
  44. to quote those.
  45.  
  46.    The other commands deal with expressions or "sexps".  The word `sexp'
  47. is derived from "s-expression", the term for a symbolic expression in
  48. Lisp.  In Emacs, the notion of `sexp' is not limited to Lisp.  It
  49. refers to an expression in the language  your program is written in.
  50. Each programming language has its own major mode, which customizes the
  51. syntax tables so that expressions in that language count as sexps.
  52.  
  53.    Sexps typically include symbols, numbers, and string constants, as
  54. well as anything contained in parentheses, brackets, or braces.
  55.  
  56.    In languages that use prefix and infix operators, such as C, it is
  57. not possible for all expressions to be sexps.  For example, C mode does
  58. not recognize `foo + bar' as an sexp, even though it is a C expression;
  59. it recognizes `foo' as one sexp and `bar' as another, with the `+' as
  60. punctuation between them.  This is a fundamental ambiguity: both `foo +
  61. bar' and `foo' are legitimate choices for the sexp to move over if
  62. point is at the `f'.  Note that `(foo + bar)' is a sexp in C mode.
  63.  
  64.    Some languages have obscure forms of syntax for expressions that
  65. nobody has bothered to make Emacs understand properly.
  66.  
  67. `C-M-f'
  68.      Move forward over an sexp (`forward-sexp').
  69.  
  70. `C-M-b'
  71.      Move backward over an sexp (`backward-sexp').
  72.  
  73. `C-M-k'
  74.      Kill sexp forward (`kill-sexp').
  75.  
  76. `C-M-u'
  77.      Move up and backward in list structure (`backward-up-list').
  78.  
  79. `C-M-d'
  80.      Move down and forward in list structure (`down-list').
  81.  
  82. `C-M-n'
  83.      Move forward over a list (`forward-list').
  84.  
  85. `C-M-p'
  86.      Move backward over a list (`backward-list').
  87.  
  88. `C-M-t'
  89.      Transpose expressions (`transpose-sexps').
  90.  
  91. `C-M-@'
  92.      Put mark after following expression (`mark-sexp').
  93.  
  94.    To move forward over an sexp, use `C-M-f' (`forward-sexp').  If the
  95. first significant character after point is an opening delimiter (`(' in
  96. Lisp; `(', `[', or `{' in C), `C-M-f' moves past the matching closing
  97. delimiter.  If the character begins a symbol, string, or number,
  98. `C-M-f' moves over that.  If the character after point is a closing
  99. delimiter, `C-M-f' just moves past it.  (This last is not really moving
  100. across an sexp; it is an exception which is included in the definition
  101. of `C-M-f' because it is as useful a behavior as anyone can think of
  102. for that situation.)
  103.  
  104.    The command `C-M-b' (`backward-sexp') moves backward over a sexp.
  105. The detailed rules are like those above for `C-M-f', but with
  106. directions reversed.  If there are any prefix characters (single quote,
  107. back quote, and comma, in Lisp) preceding the sexp, `C-M-b' moves back
  108. over them as well.
  109.  
  110.    `C-M-f' or `C-M-b' with an argument repeats that operation the
  111. specified number of times; with a negative argument, it moves in the
  112. opposite direction.
  113.  
  114.    In languages such as C where the comment-terminator can be
  115. recognized, the sexp commands move across comments as if they were
  116. whitespace.  In Lisp and other languages where comments run until the
  117. end of a line, it is very difficult to ignore comments when parsing
  118. backwards; therefore, in such languages the sexp commands treat the
  119. text of comments as if it were code.
  120.  
  121.    Killing an sexp at a time can be done with `C-M-k' (`kill-sexp').
  122. `C-M-k' kills the characters that `C-M-f' would move over.
  123.  
  124.    The "list commands", `C-M-n' (`forward-list') and `C-M-p'
  125. (`backward-list'), move over lists like the sexp commands but skip over
  126. any number of other kinds of sexps (symbols, strings, etc).  In some
  127. situations, these commands are useful because they usually ignore
  128. comments, since the comments usually do not contain any lists.
  129.  
  130.    `C-M-n' and `C-M-p' stay at the same level in parentheses, when that
  131. is possible.  To move up one (or N) levels, use `C-M-u'
  132. (`backward-up-list').  `C-M-u' moves backward up past one unmatched
  133. opening delimiter.  A positive argument serves as a repeat count; a
  134. negative argument reverses direction of motion and also requests
  135. repetition, so it moves forward and up one or more levels.
  136.  
  137.    To move down in list structure, use `C-M-d' (`down-list').  In Lisp
  138. mode, where `(' is the only opening delimiter, this is nearly the same
  139. as searching for a `('.  An argument specifies the number of levels of
  140. parentheses to go down.
  141.  
  142.    `C-M-t' (`transpose-sexps') drags the previous sexp across the next
  143. one.  An argument serves as a repeat count, and a negative argument
  144. drags backwards (thus canceling out the effect of `C-M-t' with a
  145. positive argument).  An argument of zero, rather than doing nothing,
  146. transposes the sexps ending after point and the mark.
  147.  
  148.    To make the region be the next sexp in the buffer, use `C-M-@'
  149. (`mark-sexp') which sets the mark at the same place that `C-M-f' would
  150. move to.  `C-M-@' takes arguments like `C-M-f'.  In particular, a
  151. negative argument is useful for putting the mark at the beginning of
  152. the previous sexp.
  153.  
  154.    The list and sexp commands' understanding of syntax is completely
  155. controlled by the syntax table.  Any character can, for example, be
  156. declared to be an opening delimiter and act like an open parenthesis.
  157. *Note Syntax::.
  158.  
  159. 
  160. File: xemacs.info,  Node: Defuns,  Next: Grinding,  Prev: Lists,  Up: Programs
  161.  
  162. Defuns
  163. ======
  164.  
  165.    In Emacs, a parenthetical grouping at the top level in the buffer is
  166. called a "defun".  The name derives from the fact that most top-level
  167. lists in Lisp are instances of the special form `defun', but Emacs
  168. calls any top-level parenthetical grouping counts a defun regardless of
  169. its contents or the programming language.  For example, in C, the body
  170. of a function definition is a defun.
  171.  
  172. `C-M-a'
  173.      Move to beginning of current or preceding defun
  174.      (`beginning-of-defun').
  175.  
  176. `C-M-e'
  177.      Move to end of current or following defun (`end-of-defun').
  178.  
  179. `C-M-h'
  180.      Put region around whole current or following defun (`mark-defun').
  181.  
  182.    The commands to move to the beginning and end of the current defun
  183. are `C-M-a' (`beginning-of-defun') and `C-M-e' (`end-of-defun').
  184.  
  185.    To operate on the current defun, use `C-M-h' (`mark-defun') which
  186. puts point at the beginning and the mark at the end of the current or
  187. next defun.  This is the easiest way to prepare for moving the defun to
  188. a different place.  In C mode, `C-M-h' runs the function
  189. `mark-c-function', which is almost the same as `mark-defun', but which
  190. backs up over the argument declarations, function name, and returned
  191. data type so that the entire C function is inside the region.
  192.  
  193.    To compile and evaluate the current defun, use `M-x compile-defun'.
  194. This function prints the results in the minibuffer. If you include an
  195. argument, it inserts the value in the current buffer after the defun.
  196.  
  197.    Emacs assumes that any open-parenthesis found in the leftmost column
  198. is the start of a defun.  Therefore, never put an open-parenthesis at
  199. the left margin in a Lisp file unless it is the start of a top level
  200. list.  Never put an open-brace or other opening delimiter at the
  201. beginning of a line of C code unless it starts the body of a function.
  202. The most likely problem case is when you want an opening delimiter at
  203. the start of a line inside a string.  To avoid trouble, put an escape
  204. character (`\' in C and Emacs Lisp, `/' in some other Lisp dialects)
  205. before the opening delimiter.  It will not affect the contents of the
  206. string.
  207.  
  208.    The original Emacs found defuns by moving upward a level of
  209. parentheses until there were no more levels to go up.  This required
  210. scanning back to the beginning of the buffer for every function.  To
  211. speed this up, Emacs was changed to assume that any `(' (or other
  212. character assigned the syntactic class of opening-delimiter) at the
  213. left margin is the start of a defun.  This heuristic is nearly always
  214. right; however, it mandates the convention described above.
  215.  
  216. 
  217. File: xemacs.info,  Node: Grinding,  Next: Matching,  Prev: Defuns,  Up: Programs
  218.  
  219. Indentation for Programs
  220. ========================
  221.  
  222.    The best way to keep a program properly indented ("ground") is to
  223. use Emacs to re-indent it as you change the program.  Emacs has commands
  224. to indent properly either a single line, a specified number of lines, or
  225. all of the lines inside a single parenthetical grouping.
  226.  
  227. * Menu:
  228.  
  229. * Basic Indent::
  230. * Multi-line Indent::   Commands to reindent many lines at once.
  231. * Lisp Indent::        Specifying how each Lisp function should be indented.
  232. * C Indent::        Choosing an indentation style for C code.
  233.  
  234. 
  235. File: xemacs.info,  Node: Basic Indent,  Next: Multi-line Indent,  Prev: Grinding,  Up: Grinding
  236.  
  237. Basic Program Indentation Commands
  238. ----------------------------------
  239.  
  240. `<TAB>'
  241.      Adjust indentation of current line.
  242.  
  243. `<LFD>'
  244.      Equivalent to <RET> followed by <TAB> (`newline-and-indent').
  245.  
  246.    The basic indentation command is <TAB>, which gives the current line
  247. the correct indentation as determined from the previous lines.  The
  248. function that <TAB> runs depends on the major mode; it is
  249. `lisp-indent-line' in Lisp mode, `c-indent-line' in C mode, etc.  These
  250. functions understand different syntaxes for different languages, but
  251. they all do about the same thing.  <TAB> in any programming language
  252. major mode inserts or deletes whitespace at the beginning of the
  253. current line, independent of where point is in the line.  If point is
  254. inside the whitespace at the beginning of the line, <TAB> leaves it at
  255. the end of that whitespace; otherwise, <TAB> leaves point fixed with
  256. respect to the characters around it.
  257.  
  258.    Use `C-q <TAB>' to insert a tab at point.
  259.  
  260.    When entering a large amount of new code, use <LFD>
  261. (`newline-and-indent'), which is equivalent to a <RET> followed by a
  262. <TAB>.  <LFD> creates a blank line, then gives it the appropriate
  263. indentation.
  264.  
  265.    <TAB> indents the second and following lines of the body of a
  266. parenthetical grouping each under the preceding one; therefore, if you
  267. alter one line's indentation to be nonstandard, the lines below tend to
  268. follow it.  This is the right behavior in cases where the standard
  269. result of <TAB> does not look good.
  270.  
  271.    Remember that Emacs assumes that an open-parenthesis, open-brace, or
  272. other opening delimiter at the left margin (including the indentation
  273. routines) is the start of a function.  You should therefore never have
  274. an opening delimiter in column zero that is not the beginning of a
  275. function, not even inside a string.  This restriction is vital for
  276. making the indentation commands fast. *Note Defuns::, for more
  277. information on this behavior.
  278.  
  279. 
  280. File: xemacs.info,  Node: Multi-line Indent,  Next: Lisp Indent,  Prev: Basic Indent,  Up: Grinding
  281.  
  282. Indenting Several Lines
  283. -----------------------
  284.  
  285.    Several commands are available to re-indent several lines of code
  286. which have been altered or moved to a different level in a list
  287. structure.
  288.  
  289. `C-M-q'
  290.      Re-indent all the lines within one list (`indent-sexp').
  291.  
  292. `C-u <TAB>'
  293.      Shift an entire list rigidly sideways so that its first line is
  294.      properly indented.
  295.  
  296. `C-M-\'
  297.      Re-indent all lines in the region (`indent-region').
  298.  
  299.    To re-indent the contents of a single list, position point before the
  300. beginning of it and type `C-M-q'. This key is bound to `indent-sexp' in
  301. Lisp mode, `indent-c-exp' in C mode, and bound to other suitable
  302. functions in other modes.  The indentation of the line the sexp starts
  303. on is not changed; therefore, only the relative indentation within the
  304. list, and not its position, is changed.  To correct the position as
  305. well, type a <TAB> before `C-M-q'.
  306.  
  307.    If the relative indentation within a list is correct but the
  308. indentation of its beginning is not, go to the line on which the list
  309. begins and type `C-u <TAB>'.  When you give <TAB> a numeric argument,
  310. it moves all the lines in the group, starting on the current line,
  311. sideways the same amount that the current line moves.  The command does
  312. not move lines that start inside strings, or C preprocessor lines when
  313. in C mode.
  314.  
  315.    Another way to specify a range to be re-indented is with point and
  316. mark.  The command `C-M-\' (`indent-region') applies <TAB> to every
  317. line whose first character is between point and mark.
  318.  
  319. 
  320. File: xemacs.info,  Node: Lisp Indent,  Next: C Indent,  Prev: Multi-line Indent,  Up: Grinding
  321.  
  322. Customizing Lisp Indentation
  323. ----------------------------
  324.  
  325.    The indentation pattern for a Lisp expression can depend on the
  326. function called by the expression.  For each Lisp function, you can
  327. choose among several predefined patterns of indentation, or define an
  328. arbitrary one with a Lisp program.
  329.  
  330.    The standard pattern of indentation is as follows: the second line
  331. of the expression is indented under the first argument, if that is on
  332. the same line as the beginning of the expression; otherwise, the second
  333. line is indented underneath the function name.  Each following line is
  334. indented under the previous line whose nesting depth is the same.
  335.  
  336.    If the variable `lisp-indent-offset' is non-`nil', it overrides the
  337. usual indentation pattern for the second line of an expression, so that
  338. such lines are always indented `lisp-indent-offset' more columns than
  339. the containing list.
  340.  
  341.    Certain functions override the standard pattern.  Functions whose
  342. names start with `def' always indent the second line by
  343. `lisp-body-indention' extra columns beyond the open-parenthesis
  344. starting the expression.
  345.  
  346.    Individual functions can override the standard pattern in various
  347. ways, according to the `lisp-indent-function' property of the function
  348. name.  (Note: `lisp-indent-function' was formerly called
  349. `lisp-indent-hook').  There are four possibilities for this property:
  350.  
  351. `nil'
  352.      This is the same as no property; the standard indentation pattern
  353.      is used.
  354.  
  355. `defun'
  356.      The pattern used for function names that start with `def' is used
  357.      for this function also.
  358.  
  359. a number, NUMBER
  360.      The first NUMBER arguments of the function are "distinguished"
  361.      arguments; the rest are considered the "body" of the expression.
  362.      A line in the expression is indented according to whether the
  363.      first argument on it is distinguished or not.  If the argument is
  364.      part of the body, the line is indented `lisp-body-indent' more
  365.      columns than the open-parenthesis starting the containing
  366.      expression.  If the argument is distinguished and is either the
  367.      first or second argument, it is indented twice that many extra
  368.      columns.  If the argument is distinguished and not the first or
  369.      second argument, the standard pattern is followed for that line.
  370.  
  371. a symbol, SYMBOL
  372.      SYMBOL should be a function name; that function is called to
  373.      calculate the indentation of a line within this expression.  The
  374.      function receives two arguments:
  375.     STATE
  376.           The value returned by `parse-partial-sexp' (a Lisp primitive
  377.           for indentation and nesting computation) when it parses up to
  378.           the beginning of this line.
  379.  
  380.     POS
  381.           The position at which the line being indented begins.
  382.  
  383.      It should return either a number, which is the number of columns of
  384.      indentation for that line, or a list whose first element is such a
  385.      number.  The difference between returning a number and returning a
  386.      list is that a number says that all following lines at the same
  387.      nesting level should be indented just like this one; a list says
  388.      that following lines might call for different indentations.  This
  389.      makes a difference when the indentation is computed by `C-M-q'; if
  390.      the value is a number, `C-M-q' need not recalculate indentation
  391.      for the following lines until the end of the list.
  392.  
  393. 
  394. File: xemacs.info,  Node: C Indent,  Prev: Lisp Indent,  Up: Grinding
  395.  
  396. Customizing C Indentation
  397. -------------------------
  398.  
  399.    Two variables control which commands perform C indentation and when.
  400.  
  401.    If `c-auto-newline' is non-`nil', newlines are inserted both before
  402. and after braces that you insert and after colons and semicolons.
  403. Correct C indentation is done on all the lines that are made this way.
  404.  
  405.    If `c-tab-always-indent' is non-`nil', the <TAB> command in C mode
  406. does indentation only if point is at the left margin or within the
  407. line's indentation.  If there is non-whitespace to the left of point,
  408. <TAB> just inserts a tab character in the buffer.  Normally, this
  409. variable is `nil', and <TAB> always reindents the current line.
  410.  
  411.    C does not have anything analogous to particular function names for
  412. which special forms of indentation are desirable.  However, it has a
  413. different need for customization facilities: many different styles of C
  414. indentation are in common use.
  415.  
  416.    There are six variables you can set to control the style that Emacs C
  417. mode will use.
  418.  
  419. `c-indent-level'
  420.      Indentation of C statements within surrounding block.  The
  421.      surrounding block's indentation is the indentation of the line on
  422.      which the open-brace appears.
  423.  
  424. `c-continued-statement-offset'
  425.      Extra indentation given to a substatement, such as the then-clause
  426.      of an `if' or body of a `while'.
  427.  
  428. `c-brace-offset'
  429.      Extra indentation for lines that start with an open brace.
  430.  
  431. `c-brace-imaginary-offset'
  432.      An open brace following other text is treated as if it were this
  433.      far to the right of the start of its line.
  434.  
  435. `c-argdecl-indent'
  436.      Indentation level of declarations of C function arguments.
  437.  
  438. `c-label-offset'
  439.      Extra indentation for a line that is a label, case, or default.
  440.  
  441.    The variable `c-indent-level' controls the indentation for C
  442. statements with respect to the surrounding block.  In the example:
  443.  
  444.          {
  445.            foo ();
  446.  
  447. the difference in indentation between the lines is `c-indent-level'.
  448. Its standard value is 2.
  449.  
  450.    If the open-brace beginning the compound statement is not at the
  451. beginning of its line, the `c-indent-level' is added to the indentation
  452. of the line, not the column of the open-brace.  For example,
  453.  
  454.      if (losing) {
  455.        do_this ();
  456.  
  457. One popular indentation style is that which results from setting
  458. `c-indent-level' to 8 and putting open-braces at the end of a line in
  459. this way.  Another popular style prefers to put the open-brace on a
  460. separate line.
  461.  
  462.    In fact, the value of the variable `c-brace-imaginary-offset' is
  463. also added to the indentation of such a statement.  Normally this
  464. variable is zero.  Think of this variable as the imaginary position of
  465. the open brace, relative to the first non-blank character on the line.
  466. By setting the variable to 4 and `c-indent-level' to 0, you can get
  467. this style:
  468.  
  469.      if (x == y) {
  470.          do_it ();
  471.          }
  472.  
  473.    When `c-indent-level' is zero, the statements inside most braces
  474. line up exactly under the open brace.  An exception are braces in column
  475. zero, like those surrounding a function's body.  The statements inside
  476. those braces are not placed at column zero.  Instead, `c-brace-offset'
  477. and `c-continued-statement-offset' (see below) are added to produce a
  478. typical offset between brace levels, and the statements are indented
  479. that far.
  480.  
  481.    `c-continued-statement-offset' controls the extra indentation for a
  482. line that starts within a statement (but not within parentheses or
  483. brackets).  These lines are usually statements inside other statements,
  484. like the then-clauses of `if' statements and the bodies of `while'
  485. statements.  The `c-continued-statement-offset' parameter determines
  486. the difference in indentation between the two lines in:
  487.  
  488.      if (x == y)
  489.        do_it ();
  490.  
  491. The default value for `c-continued-statement-offset' is 2.  Some
  492. popular indentation styles correspond to a value of zero for
  493. `c-continued-statement-offset'.
  494.  
  495.    `c-brace-offset' is the extra indentation given to a line that
  496. starts with an open-brace.  Its standard value is zero; compare:
  497.  
  498.      if (x == y)
  499.        {
  500.  
  501. with:
  502.  
  503.      if (x == y)
  504.        do_it ();
  505.  
  506. If you set `c-brace-offset' to 4, the first example becomes:
  507.  
  508.      if (x == y)
  509.            {
  510.  
  511.    `c-argdecl-indent' controls the indentation of declarations of the
  512. arguments of a C function.  It is absolute: argument declarations
  513. receive exactly `c-argdecl-indent' spaces.  The standard value is 5 and
  514. results in code like this:
  515.  
  516.      char *
  517.      index (string, char)
  518.           char *string;
  519.           int char;
  520.  
  521.    `c-label-offset' is the extra indentation given to a line that
  522. contains a label, a case statement, or a `default:' statement.  Its
  523. standard value is -2 and results in code like this:
  524.  
  525.      switch (c)
  526.        {
  527.        case 'x':
  528.  
  529. If `c-label-offset' were zero, the same code would be indented as:
  530.  
  531.      switch (c)
  532.        {
  533.          case 'x':
  534.  
  535. This example assumes that the other variables above also have their
  536. default values.
  537.  
  538.    Using the indentation style produced by the default settings of the
  539. variables just discussed and putting open braces on separate lines
  540. produces clear and readable files.  For an example, look at any of the C
  541. source files of XEmacs.
  542.  
  543. 
  544. File: xemacs.info,  Node: Matching,  Next: Comments,  Prev: Grinding,  Up: Programs
  545.  
  546. Automatic Display of Matching Parentheses
  547. =========================================
  548.  
  549.    The Emacs parenthesis-matching feature shows you automatically how
  550. parentheses match in the text.  Whenever a self-inserting character that
  551. is a closing delimiter is typed, the cursor moves momentarily to the
  552. location of the matching opening delimiter, provided that is visible on
  553. the screen.  If it is not on the screen, some text starting with that
  554. opening delimiter is displayed in the echo area.  Either way, you see
  555. the grouping you are closing off.
  556.  
  557.    In Lisp, automatic matching applies only to parentheses.  In C, it
  558. also applies to braces and brackets.  Emacs knows which characters to
  559. regard as matching delimiters based on the syntax table set by the major
  560. mode.  *Note Syntax::.
  561.  
  562.    If the opening delimiter and closing delimiter are mismatched--as in
  563. `[x)'--the echo area displays a warning message.  The correct matches
  564. are specified in the syntax table.
  565.  
  566.    Two variables control parenthesis matching displays.
  567. `blink-matching-paren' turns the feature on or off. The default is `t'
  568. (match display is on); `nil' turns it off.
  569. `blink-matching-paren-distance' specifies how many characters back
  570. Emacs searches to find a matching opening delimiter.  If the match is
  571. not found in the specified region, scanning stops, and nothing is
  572. displayed.  This prevents wasting lots of time scanning when there is no
  573. match.  The default is 4000.
  574.  
  575. 
  576. File: xemacs.info,  Node: Comments,  Next: Balanced Editing,  Prev: Matching,  Up: Programs
  577.  
  578. Manipulating Comments
  579. =====================
  580.  
  581.    The comment commands insert, kill and align comments.
  582.  
  583. `M-;'
  584.      Insert or align comment (`indent-for-comment').
  585.  
  586. `C-x ;'
  587.      Set comment column (`set-comment-column').
  588.  
  589. `C-u - C-x ;'
  590.      Kill comment on current line (`kill-comment').
  591.  
  592. `M-<LFD>'
  593.      Like <RET> followed by inserting and aligning a comment
  594.      (`indent-new-comment-line').
  595.  
  596.    The command that creates a comment is `Meta-;'
  597. (`indent-for-comment').  If there is no comment already on the line, a
  598. new comment is created and aligned at a specific column called the
  599. "comment column".  Emacs creates the comment by inserting the string at
  600. the value of `comment-start'; see below.  Point is left after that
  601. string.  If the text of the line extends past the comment column,
  602. indentation is done to a suitable boundary (usually, at least one space
  603. is inserted).  If the major mode has specified a string to terminate
  604. comments, that string is inserted after point, to keep the syntax valid.
  605.  
  606.    You can also use `Meta-;' to align an existing comment.  If a line
  607. already contains the string that starts comments, `M-;' just moves
  608. point after it and re-indents it to the conventional place.  Exception:
  609. comments starting in column 0 are not moved.
  610.  
  611.    Some major modes have special rules for indenting certain kinds of
  612. comments in certain contexts.  For example, in Lisp code, comments which
  613. start with two semicolons are indented as if they were lines of code,
  614. instead of at the comment column.  Comments which start with three
  615. semicolons are supposed to start at the left margin.  Emacs understands
  616. these conventions by indenting a double-semicolon comment using <TAB>
  617. and by not changing the indentation of a triple-semicolon comment at
  618. all.
  619.  
  620.      ;; This function is just an example.
  621.      ;;; Here either two or three semicolons are appropriate.
  622.      (defun foo (x)
  623.      ;;; And now, the first part of the function:
  624.        ;; The following line adds one.
  625.        (1+ x))           ; This line adds one.
  626.  
  627.    In C code, a comment preceded on its line by nothing but whitespace
  628. is indented like a line of code.
  629.  
  630.    Even when an existing comment is properly aligned, `M-;' is still
  631. useful for moving directly to the start of the comment.
  632.  
  633.    `C-u - C-x ;' (`kill-comment') kills the comment on the current
  634. line, if there is one.  The indentation before the start of the comment
  635. is killed as well.  If there does not appear to be a comment in the
  636. line, nothing happens.  To reinsert the comment on another line, move
  637. to the end of that line, type first `C-y', and then `M-;' to realign
  638. the comment.  Note that `C-u - C-x ;' is not a distinct key; it is `C-x
  639. ;' (`set-comment-column') with a negative argument.  That command is
  640. programmed to call `kill-comment' when called with a negative argument.
  641. However, `kill-comment' is a valid command which you could bind
  642. directly to a key if you wanted to.
  643.  
  644. Multiple Lines of Comments
  645. --------------------------
  646.  
  647.    If you are typing a comment and want to continue it on another line,
  648. use the command `Meta-<LFD>' (`indent-new-comment-line'), which
  649. terminates the comment you are typing, creates a new blank line
  650. afterward, and begins a new comment indented under the old one.  If
  651. Auto Fill mode is on and you go past the fill column while typing, the
  652. comment is continued in just this fashion.  If point is not at the end
  653. of the line when you type `M-<LFD>', the text on the rest of the line
  654. becomes part of the new comment line.
  655.  
  656. Options Controlling Comments
  657. ----------------------------
  658.  
  659.    The comment column is stored in the variable `comment-column'.  You
  660. can explicitly set it to a number.  Alternatively, the command `C-x ;'
  661. (`set-comment-column') sets the comment column to the column point is
  662. at.  `C-u C-x ;' sets the comment column to match the last comment
  663. before point in the buffer, and then calls `Meta-;' to align the
  664. current line's comment under the previous one.  Note that `C-u - C-x ;'
  665. runs the function `kill-comment' as described above.
  666.  
  667.    `comment-column' is a per-buffer variable; altering the variable
  668. affects only the current buffer.  You can also change the default value.
  669. *Note Locals::.  Many major modes initialize this variable for the
  670. current buffer.
  671.  
  672.    The comment commands recognize comments based on the regular
  673. expression that is the value of the variable `comment-start-skip'.
  674. This regexp should not match the null string.  It may match more than
  675. the comment starting delimiter in the strictest sense of the word; for
  676. example, in C mode the value of the variable is `"/\\*+ *"', which
  677. matches extra stars and spaces after the `/*' itself.  (Note that `\\'
  678. is needed in Lisp syntax to include a `\' in the string, which is needed
  679. to deny the first star its special meaning in regexp syntax.  *Note
  680. Regexps::.)
  681.  
  682.    When a comment command makes a new comment, it inserts the value of
  683. `comment-start' to begin it.  The value of `comment-end' is inserted
  684. after point and will follow the text you will insert into the comment.
  685. In C mode, `comment-start' has the value `"/* "' and `comment-end' has
  686. the value `" */"'.
  687.  
  688.    `comment-multi-line' controls how `M-<LFD>'
  689. (`indent-new-comment-line') behaves when used inside a comment.  If
  690. `comment-multi-line' is `nil', as it normally is, then `M-<LFD>'
  691. terminates the comment on the starting line and starts a new comment on
  692. the new following line.  If `comment-multi-line' is not `nil', then
  693. `M-<LFD>' sets up the new following line as part of the same comment
  694. that was found on the starting line.  This is done by not inserting a
  695. terminator on the old line and not inserting a starter on the new line.
  696. In languages where multi-line comments are legal, the value you choose
  697. for this variable is a matter of taste.
  698.  
  699.    The variable `comment-indent-hook' should contain a function that is
  700. called to compute the indentation for a newly inserted comment or for
  701. aligning an existing comment.  Major modes set this variable
  702. differently.  The function is called with no arguments, but with point
  703. at the beginning of the comment, or at the end of a line if a new
  704. comment is to be inserted.  The function should return the column in
  705. which the comment ought to start.  For example, in Lisp mode, the
  706. indent hook function bases its decision on the number of semicolons
  707. that begin an existing comment and on the code in the preceding lines.
  708.  
  709. 
  710. File: xemacs.info,  Node: Balanced Editing,  Next: Lisp Completion,  Prev: Comments,  Up: Programs
  711.  
  712. Editing Without Unbalanced Parentheses
  713. ======================================
  714.  
  715. `M-('
  716.      Put parentheses around next sexp(s) (`insert-parentheses').
  717.  
  718. `M-)'
  719.      Move past next close parenthesis and re-indent
  720.      (`move-over-close-and-reindent').
  721.  
  722.    The commands `M-(' (`insert-parentheses') and `M-)'
  723. (`move-over-close-
  724. and-reindent') are designed to facilitate a style of editing which
  725. keeps parentheses balanced at all times.  `M-(' inserts a pair of
  726. parentheses, either together as in `()', or, if given an argument,
  727. around the next several sexps, and leaves point after the open
  728. parenthesis.  Instead of typing `( F O O )', you can type `M-( F O O',
  729. which has the same effect except for leaving the cursor before the
  730. close parenthesis.  You can then type `M-)', which moves past the close
  731. parenthesis, deletes any indentation preceding it (in this example
  732. there is none), and indents with <LFD> after it.
  733.  
  734. 
  735. File: xemacs.info,  Node: Lisp Completion,  Next: Documentation,  Prev: Balanced Editing,  Up: Programs
  736.  
  737. Completion for Lisp Symbols
  738. ===========================
  739.  
  740.    Completion usually happens in the minibuffer.  An exception is
  741. completion for Lisp symbol names, which is available in all buffers.
  742.  
  743.    The command `M-<TAB>' (`lisp-complete-symbol') takes the partial
  744. Lisp symbol before point to be an abbreviation, and compares it against
  745. all non-trivial Lisp symbols currently known to Emacs.  Any additional
  746. characters that they all have in common are inserted at point.
  747. Non-trivial symbols are those that have function definitions, values, or
  748. properties.
  749.  
  750.    If there is an open-parenthesis immediately before the beginning of
  751. the partial symbol, only symbols with function definitions are
  752. considered as completions.
  753.  
  754.    If the partial name in the buffer has more than one possible
  755. completion and they have no additional characters in common, a list of
  756. all possible completions is displayed in another window.
  757.  
  758. 
  759. File: xemacs.info,  Node: Documentation,  Next: Change Log,  Prev: Lisp Completion,  Up: Programs
  760.  
  761. Documentation Commands
  762. ======================
  763.  
  764.    As you edit Lisp code to be run in Emacs, you can use the commands
  765. `C-h f' (`describe-function') and `C-h v' (`describe-variable') to
  766. print documentation of functions and variables you want to call.  These
  767. commands use the minibuffer to read the name of a function or variable
  768. to document, and display the documentation in a window.
  769.  
  770.    For extra convenience, these commands provide default arguments
  771. based on the code in the neighborhood of point.  `C-h f' sets the
  772. default to the function called in the innermost list containing point.
  773. `C-h v' uses the symbol name around or adjacent to point as its default.
  774.  
  775.    The `M-x manual-entry' command gives you access to documentation on
  776. Unix commands, system calls, and libraries.  The command reads a topic
  777. as an argument, and displays the Unix manual page for that topic.
  778. `manual-entry' always searches all 8 sections of the manual and
  779. concatenates all the entries it finds.  For example, the topic
  780. `termcap' finds the description of the termcap library from section 3,
  781. followed by the description of the termcap data base from section 5.
  782.  
  783. 
  784. File: xemacs.info,  Node: Change Log,  Next: Tags,  Prev: Documentation,  Up: Programs
  785.  
  786. Change Logs
  787. ===========
  788.  
  789.    The Emacs command `M-x add-change-log-entry' helps you keep a record
  790. of when and why you have changed a program.  It assumes that you have a
  791. file in which you write a chronological sequence of entries describing
  792. individual changes.  The default is to store the change entries in a
  793. file called `ChangeLog' in the same directory as the file you are
  794. editing.  The same `ChangeLog' file therefore records changes for all
  795. the files in a directory.
  796.  
  797.    A change log entry starts with a header line that contains your name
  798. and the current date.  Except for these header lines, every line in the
  799. change log starts with a tab.  One entry can describe several changes;
  800. each change starts with a line starting with a tab and a star.  `M-x
  801. add-change-log-entry' visits the change log file and creates a new entry
  802. unless the most recent entry is for today's date and your name.  In
  803. either case, it adds a new line to start the description of another
  804. change just after the header line of the entry.  When `M-x
  805. add-change-log-entry' is finished, all is prepared for you to edit in
  806. the description of what you changed and how.  You must then save the
  807. change log file yourself.
  808.  
  809.    The change log file is always visited in Indented Text mode, which
  810. means that <LFD> and auto-filling indent each new line like the previous
  811. line.  This is convenient for entering the contents of an entry, which
  812. must be indented.  *Note Text Mode::.
  813.  
  814.    Here is an example of the formatting conventions used in the change
  815. log for Emacs:
  816.  
  817.      Wed Jun 26 19:29:32 1985  Richard M. Stallman  (rms at mit-prep)
  818.      
  819.              * xdisp.c (try_window_id):
  820.              If C-k is done at end of next-to-last line,
  821.              this fn updates window_end_vpos and cannot leave
  822.              window_end_pos nonnegative (it is zero, in fact).
  823.              If display is preempted before lines are output,
  824.              this is inconsistent.  Fix by setting
  825.              blank_end_of_window to nonzero.
  826.      
  827.      Tue Jun 25 05:25:33 1985  Richard M. Stallman  (rms at mit-prep)
  828.      
  829.              * cmds.c (Fnewline):
  830.              Call the auto fill hook if appropriate.
  831.      
  832.              * xdisp.c (try_window_id):
  833.              If point is found by compute_motion after xp, record that
  834.              permanently.  If display_text_line sets point position wrong
  835.              (case where line is killed, point is at eob and that line is
  836.              not displayed), set it again in final compute_motion.
  837.  
  838. 
  839. File: xemacs.info,  Node: Tags,  Next: Fortran,  Prev: Change Log,  Up: Programs
  840.  
  841. Tags Tables
  842. ===========
  843.  
  844.    A "tags table" is a description of how a multi-file program is
  845. broken up into files.  It lists the names of the component files and the
  846. names and positions of the functions (or other named subunits) in each
  847. file.  Grouping the related files makes it possible to search or replace
  848. through all the files with one command.  Recording the function names
  849. and positions makes possible the `M-.'  command which finds the
  850. definition of a function by looking up which of the files it is in.
  851.  
  852.    Tags tables are stored in files called "tags table files".  The
  853. conventional name for a tags table file is `TAGS'.
  854.  
  855.    Each entry in the tags table records the name of one tag, the name
  856. of the file that the tag is defined in (implicitly), and the position
  857. in that file of the tag's definition.
  858.  
  859.    Just what names from the described files are recorded in the tags
  860. table depends on the programming language of the described file.  They
  861. normally include all functions and subroutines, and may also include
  862. global variables, data types, and anything else convenient.  Each name
  863. recorded is called a "tag".
  864.  
  865. * Menu:
  866.  
  867. * Tag Syntax::        Tag syntax for various types of code and text files.
  868. * Create Tags Table::    Creating a tags table with `etags'.
  869. * Select Tags Table::    How to visit a tags table.
  870. * Find Tag::        Commands to find the definition of a specific tag.
  871. * Tags Search::        Using a tags table for searching and replacing.
  872. * List Tags::        Listing and finding tags defined in a file.
  873.  
  874. 
  875. File: xemacs.info,  Node: Tag Syntax,  Next: Create Tags Table,  Up: Tags
  876.  
  877. Source File Tag Syntax
  878. ----------------------
  879.  
  880.    Here is how tag syntax is defined for the most popular languages:
  881.  
  882.    * In C code, any C function or typedef is a tag, and so are
  883.      definitions of `struct', `union' and `enum'.  `#define' macro
  884.      definitions and `enum' constants are also tags, unless you specify
  885.      `--no-defines' when making the tags table.  Similarly, global
  886.      variables are tags, unless you specify `--no-globals'.  Use of
  887.      `--no-globals' and `--no-defines' can make the tags table file
  888.      much smaller.
  889.  
  890.    * In C++ code, in addition to all the tag constructs of C code,
  891.      member functions are also recognized, and optionally member
  892.      variables if you use the `--members' option.  Tags for variables
  893.      and functions in classes are named `CLASS::VARIABLE' and
  894.      `CLASS::FUNCTION'.
  895.  
  896.    * In Java code, tags include all the constructs recognized in C++,
  897.      plus the `extends' and `implements' constructs.  Tags for variables
  898.      and functions in classes are named `CLASS.VARIABLE' and
  899.      `CLASS.FUNCTION'.
  900.  
  901.    * In LaTeX text, the argument of any of the commands `\chapter',
  902.      `\section', `\subsection', `\subsubsection', `\eqno', `\label',
  903.      `\ref', `\cite', `\bibitem', `\part', `\appendix', `\entry', or
  904.      `\index', is a tag.
  905.  
  906.      Other commands can make tags as well, if you specify them in the
  907.      environment variable `TEXTAGS' before invoking `etags'.  The value
  908.      of this environment variable should be a colon-separated list of
  909.      commands names.  For example,
  910.  
  911.           TEXTAGS="def:newcommand:newenvironment"
  912.           export TEXTAGS
  913.  
  914.      specifies (using Bourne shell syntax) that the commands `\def',
  915.      `\newcommand' and `\newenvironment' also define tags.
  916.  
  917.    * In Lisp code, any function defined with `defun', any variable
  918.      defined with `defvar' or `defconst', and in general the first
  919.      argument of any expression that starts with `(def' in column zero,
  920.      is a tag.
  921.  
  922.    * In Scheme code, tags include anything defined with `def' or with a
  923.      construct whose name starts with `def'.  They also include
  924.      variables set with `set!' at top level in the file.
  925.  
  926.    Several other languages are also supported:
  927.  
  928.    * In assembler code, labels appearing at the beginning of a line,
  929.      followed by a colon, are tags.
  930.  
  931.    * In Bison or Yacc input files, each rule defines as a tag the
  932.      nonterminal it constructs.  The portions of the file that contain
  933.      C code are parsed as C code.
  934.  
  935.    * In Cobol code, paragraphs names are the tags, i.e. any word
  936.      starting in column 8 and followed by a full stop.
  937.  
  938.    * In Erlang code, the tags are the functions, records, and macros
  939.      defined in the file.
  940.  
  941.    * In Fortran code, functions and subroutines are tags.
  942.  
  943.    * In Objective C code, tags include Objective C definitions for
  944.      classes, class categories, methods and protocols.
  945.  
  946.    * In Pascal code, the tags are the functions and procedures defined
  947.      in the file.
  948.  
  949.    * In Perl code, the tags are the procedures defined by the `sub'
  950.      keyword.
  951.  
  952.    * In Postscript code, the tags are the functions.
  953.  
  954.    * In Prolog code, a tag name appears at the left margin.
  955.  
  956.    You can also generate tags based on regexp matching (*note Create
  957. Tags Table::.) to handle other formats and languages.
  958.  
  959. 
  960. File: xemacs.info,  Node: Create Tags Table,  Next: Select Tags Table,  Prev: Tag Syntax,  Up: Tags
  961.  
  962. Creating Tags Tables
  963. --------------------
  964.  
  965.    The `etags' program is used to create a tags table file.  It knows
  966. the syntax of several languages, as described in *Note Tag Syntax::.
  967. Here is how to run `etags':
  968.  
  969.      etags INPUTFILES...
  970.  
  971. The `etags' program reads the specified files, and writes a tags table
  972. named `TAGS' in the current working directory.  `etags' recognizes the
  973. language used in an input file based on its file name and contents.
  974. You can specify the language with the `--language=NAME' option,
  975. described below.
  976.  
  977.    If the tags table data become outdated due to changes in the files
  978. described in the table, the way to update the tags table is the same
  979. way it was made in the first place.  It is not necessary to do this
  980. often.
  981.  
  982.    If the tags table fails to record a tag, or records it for the wrong
  983. file, then Emacs cannot possibly find its definition.  However, if the
  984. position recorded in the tags table becomes a little bit wrong (due to
  985. some editing in the file that the tag definition is in), the only
  986. consequence is a slight delay in finding the tag.  Even if the stored
  987. position is very wrong, Emacs will still find the tag, but it must
  988. search the entire file for it.
  989.  
  990.    So you should update a tags table when you define new tags that you
  991. want to have listed, or when you move tag definitions from one file to
  992. another, or when changes become substantial.  Normally there is no need
  993. to update the tags table after each edit, or even every day.
  994.  
  995.    One tags table can effectively include another.  Specify the included
  996. tags file name with the `--include=FILE' option when creating the file
  997. that is to include it.  The latter file then acts as if it contained
  998. all the files specified in the included file, as well as the files it
  999. directly contains.
  1000.  
  1001.    If you specify the source files with relative file names when you run
  1002. `etags', the tags file will contain file names relative to the
  1003. directory where the tags file was initially written.  This way, you can
  1004. move an entire directory tree containing both the tags file and the
  1005. source files, and the tags file will still refer correctly to the source
  1006. files.
  1007.  
  1008.    If you specify absolute file names as arguments to `etags', then the
  1009. tags file will contain absolute file names.  This way, the tags file
  1010. will still refer to the same files even if you move it, as long as the
  1011. source files remain in the same place.  Absolute file names start with
  1012. `/', or with `DEVICE:/' on MS-DOS and Windows.
  1013.  
  1014.    When you want to make a tags table from a great number of files, you
  1015. may have problems listing them on the command line, because some systems
  1016. have a limit on its length.  The simplest way to circumvent this limit
  1017. is to tell `etags' to read the file names from its standard input, by
  1018. typing a dash in place of the file names, like this:
  1019.  
  1020.      find . -name "*.[chCH]" -print | etags -
  1021.  
  1022.    Use the option `--language=NAME' to specify the language explicitly.
  1023. You can intermix these options with file names; each one applies to
  1024. the file names that follow it.  Specify `--language=auto' to tell
  1025. `etags' to resume guessing the language from the file names and file
  1026. contents.  Specify `--language=none' to turn off language-specific
  1027. processing entirely; then `etags' recognizes tags by regexp matching
  1028. alone.  `etags --help' prints the list of the languages `etags' knows,
  1029. and the file name rules for guessing the language.
  1030.  
  1031.    The `--regex' option provides a general way of recognizing tags
  1032. based on regexp matching.  You can freely intermix it with file names.
  1033. Each `--regex' option adds to the preceding ones, and applies only to
  1034. the following files.  The syntax is:
  1035.  
  1036.      --regex=/TAGREGEXP[/NAMEREGEXP]/
  1037.  
  1038. where TAGREGEXP is used to match the lines to tag.  It is always
  1039. anchored, that is, it behaves as if preceded by `^'.  If you want to
  1040. account for indentation, just match any initial number of blanks by
  1041. beginning your regular expression with `[ \t]*'.  In the regular
  1042. expressions, `\' quotes the next character, and `\t' stands for the tab
  1043. character.  Note that `etags' does not handle the other C escape
  1044. sequences for special characters.
  1045.  
  1046.    The syntax of regular expressions in `etags' is the same as in
  1047. Emacs, augmented with the "interval operator", which works as in `grep'
  1048. and `ed'.  The syntax of an interval operator is `\{M,N\}', and its
  1049. meaning is to match the preceding expression at least M times and up to
  1050. N times.
  1051.  
  1052.    You should not match more characters with TAGREGEXP than that needed
  1053. to recognize what you want to tag.  If the match is such that more
  1054. characters than needed are unavoidably matched by TAGREGEXP, you may
  1055. find useful to add a NAMEREGEXP, in order to narrow the tag scope.  You
  1056. can find some examples below.
  1057.  
  1058.    The `-R' option deletes all the regexps defined with `--regex'
  1059. options.  It applies to the file names following it, as you can see
  1060. from the following example:
  1061.  
  1062.      etags --regex=/REG1/ voo.doo --regex=/REG2/ \
  1063.          bar.ber -R --lang=lisp los.er
  1064.  
  1065. Here `etags' chooses the parsing language for `voo.doo' and `bar.ber'
  1066. according to their contents.  `etags' also uses REG1 to recognize
  1067. additional tags in `voo.doo', and both REG1 and REG2 to recognize
  1068. additional tags in `bar.ber'.  `etags' uses the Lisp tags rules, and no
  1069. regexp matching, to recognize tags in `los.er'.
  1070.  
  1071.    Here are some more examples.  The regexps are quoted to protect them
  1072. from shell interpretation.
  1073.  
  1074. Tag the `DEFVAR' macros in the emacs source files:
  1075.  
  1076.      --regex='/[ \t]*DEFVAR_[A-Z_ \t(]+"\([^"]+\)"/'
  1077.  
  1078. Tag VHDL files (this example is a single long line, broken here for
  1079. formatting reasons):
  1080.  
  1081.      --language=none
  1082.      --regex='/[ \t]*\(ARCHITECTURE\|CONFIGURATION\) +[^ ]* +OF/'
  1083.      --regex='/[ \t]*\(ATTRIBUTE\|ENTITY\|FUNCTION\|PACKAGE\
  1084.      \( BODY\)?\|PROCEDURE\|PROCESS\|TYPE\)[ \t]+\([^ \t(]+\)/\3/'
  1085.  
  1086. Tag TCL files (this last example shows the usage of a NAMEREGEXP):
  1087.  
  1088.      --lang=none --regex='/proc[ \t]+\([^ \t]+\)/\1/'
  1089.  
  1090.    For a list of the other available `etags' options, execute `etags
  1091. --help'.
  1092.  
  1093.